import org.junit.Test;
import test.ListNode;

/**
 * 3  给定两个链表的头节点，headA和headB ，请找出两个表相交的节点，没有返回null
 */
public class getIntersctionNode {

    @Test
    public void clibe() {
        ListNode list1 = new ListNode(1, new ListNode(2));
        System.out.println(test1(list1,list1));
    }

    public ListNode test1(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;
        ListNode pA = headA, pB = headB;
        while (pA != pB) {
            pA = pA == null ? headB : pA.getNext();
            pB = pB == null ? headA : pB.getNext();
        }
        return pA;
    }
}
